/**
 * Created by sicongdu on 17-11-21.
 */

var model = require("./model");

const start = "<!DOCTYPE html><html><head><meta charset=\"UTF-8\">" +
    "<title>teacher</title></head><body>";

const end = "\</body></html>";

var teacher = (req, res, tch) => {
    var teach = "";
    switch (tch) {
        case 1:
            teach = "吴振宇";
            break;
        case 2:
            teach = "范绍帅";
            break;
        case 3:
            teach = "聂高峰";
            break;
        case 4:
            teach = "王生楚";
            break;
        case 5:
            teach = "赵敏";
            break;
    }
    var wherestr = {
        teacher: teach,
        number1: req.body.number
    };

    model.findOne(wherestr, (err, documents) => {
        if (err) {
            res.send("database error!!!");
            res.end();
        }else if (documents == null) {
            res.send("This group has not signed in yet");
            res.end();
        }else{
            var send = start;

            send += '\<form method="post" action="http://www.ourspark.org/mark">'

            send += "\<p>" + documents.name1 + "\<p/>";
            send += '\<input type="radio" id="_1_1" name="mark1" value="A">' +
                '\<label for="_1_1">A</label><br />'+
                '\<input type="radio" id="_1_2" name="mark1" value="B">'+
                '\<label for="_1_2">B</label><br />'+
                '\<input type="radio" id="_1_3" name="mark1" value="C">'+
                '\<label for="_1_3">C</label><br /><br/>';

            send += "\<p>" + documents.name2 + "\<p/>";
            send += '\<input type="radio" id="_2_1" name="mark2" value="A">' +
                '\<label for="_2_1">A</label><br />'+
                '\<input type="radio" id="_2_2" name="mark2" value="B">'+
                '\<label for="_2_2">B</label><br />'+
                '\<input type="radio" id="_2_3" name="mark2" value="C">'+
                '\<label for="_2_3">C</label><br /><br/>';

            send += "\<p>" + documents.name3 + "\<p/>";
            send += '\<input type="radio" id="_3_1" name="mark3" value="A">' +
                '\<label for="_3_1">A</label><br />'+
                '\<input type="radio" id="_3_2" name="mark3" value="B">'+
                '\<label for="_3_2">B</label><br />'+
                '\<input type="radio" id="_3_3" name="mark3" value="C">'+
                '\<label for="_3_3">C</label><br /><br/>';

            send += "\<p>" + documents.name4 + "\<p/>";
            send += '\<input type="radio" id="_4_1" name="mark4" value="A">' +
                '\<label for="_4_1">A</label><br />'+
                '\<input type="radio" id="_4_2" name="mark4" value="B">'+
                '\<label for="_4_2">B</label><br />'+
                '\<input type="radio" id="_4_3" name="mark4" value="C">'+
                '\<label for="_4_3">C</label><br /><br/>';

            send += '<input name="number1" hidden="hidden" value="';
            send += wherestr.number1;
            send += '">';

            send += '\<input type="submit" value="提交" />'

            send += '\</form>'

            send += end;

            res.send(send);
            res.end();
        }


    });
};

module.exports = teacher;